﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="XnReader.WinRT.BookReader"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XnReader.WinRT"
    xmlns:common="using:XnReader.WinRT.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="ivsBookReader" Source="{Binding Chapters}"/>
        <CollectionViewSource x:Name="ivsMaxChapter" Source="{Binding MaxChapters}"/>
        <DataTemplate x:Key="lvItemBookReader">
            <StackPanel Orientation="Horizontal" Width="300" VerticalAlignment="Center">
                <Border Width="40" Height="40" VerticalAlignment="Center" HorizontalAlignment="Center" Background="#7F040404">
                    <TextBlock  Width="40" Text="{Binding flag}" Foreground="White" FontSize="18" Margin="0,10,0,0" FontFamily="Microsoft YaHei" TextAlignment="Center"/>
                </Border>
                <Border Height="40" Margin="5,0,0,0" HorizontalAlignment="Left">
                    <TextBlock FontSize="14" Margin="0,10,0,0" Text="{Binding chaptername}" FontFamily="Microsoft YaHei"/>
                </Border>
            </StackPanel>
        </DataTemplate>
    </Page.Resources>
    <!--<common:LayoutAwarePage.TopAppBar>
        <AppBar x:Name="barNav" Height="140" Background="#E5040404" >
            <local:Navigation x:Name="navTop" Margin="60,0,40,0" />
        </AppBar>
    </common:LayoutAwarePage.TopAppBar>-->

    <!--
        此网格用作定义以下两行的页的根面板:
        * 第 0 行包含后退按钮和页标题
        * 第 1 行包含页布局的其余部分
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.Background>
            <ImageBrush ImageSource="/Assets/background_default.png"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- 在大多数视图状态中使用的水平滚动网格-->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="116,136,116,46"
            ItemsSource="{Binding Source={StaticResource ivsBookReader}}"
            ItemTemplate="{StaticResource lvItemBookReader}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemGridViewItemClick">
            <GridView.Header>
                <ListView x:Name="lvWebsite"
                    SelectionMode="None"
                    IsItemClickEnabled="True"
                    IsSwipeEnabled="false"
                    ItemsSource="{Binding Source={StaticResource ivsMaxChapter}}"
                    ItemTemplate="{StaticResource dtBookReaderWebsiteItem}" ItemClick="LvWebsiteItemClick"
                    />
            </GridView.Header>
            <GridView.ItemContainerStyle>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Margin" Value="52,0,0,10"/>
                </Style>
            </GridView.ItemContainerStyle>
        </GridView>

        <!-- 垂直滚动列表仅在对齐后使用-->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemsListView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource ivsBookReader}}"
            ItemTemplate="{StaticResource lvItemBookReader}"
            SelectionMode="None"
            IsSwipeEnabled="false">
            <ListView.Header>
                <ListView 
                    SelectionMode="None"
                    IsItemClickEnabled="True"
                    IsSwipeEnabled="false"
                    ItemsSource="{Binding Source={StaticResource ivsMaxChapter}}"
                    ItemTemplate="{StaticResource dtBookReaderWebsiteItem}" ItemClick="LvWebsiteItemClick"
                    />
            </ListView.Header>
        </ListView>
        <ProgressRing Width="80" Height="80" x:Name="pbLoading"  Grid.Row="1" IsActive="True"></ProgressRing>
        <!-- 后退按钮和页标题-->
        <Grid DataContext="{Binding Chapter}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <StackPanel x:Name="spHeader" Orientation="Horizontal" Grid.Column="1">
                <TextBlock  Text="{Binding articlename}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
                <TextBlock Text="(" IsHitTestVisible="false" Style="{StaticResource PageSubheaderTextStyle}"/>
                <TextBlock Text="{Binding webname}" IsHitTestVisible="false" Style="{StaticResource PageSubheaderTextStyle}"/>
                <TextBlock Text="目录)" IsHitTestVisible="false" Style="{StaticResource PageSubheaderTextStyle}"/>
            </StackPanel>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- 视觉状态反映应用程序的视图状态-->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- 整页采用较窄的 100 像素页边距约定(纵向)-->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="navTop" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="5,0,5,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    对齐后，后退按钮和标题的样式将有所不同，并且列表表示形式将被
                    所有视图状态中显示的网格所替代
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
